package DynamicProgramming;

public class _63_UniquePathsII {
    public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        int length = obstacleGrid.length;
        int weigh = obstacleGrid[0].length;
        int[][] dp = new int[length][weigh];
        if (obstacleGrid[0][0] == 0) {
            dp[0][0] = 1;
        }
        for (int i = 0; i < length; i++) {
            for (int j = 0; j < weigh; j++) {
                if (obstacleGrid[i][j] == 0) {
                    if (i - 1 > -1) {
                        dp[i][j] += dp[i - 1][j];
                    }
                    if (j - 1 > -1) {
                        dp[i][j] += dp[i][j - 1];
                    }
                }
            }
        }
        return dp[length - 1][weigh - 1];
    }
}
